// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2009-10-26 21:59:38


// Source File Name:   TABLESWITCH.java

package com.vhly.classfile.bytecode;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

// Referenced classes of package com.vhly.classfile.bytecode:
//            BaseCode

public class TABLESWITCH
        implements BaseCode {

    private int offset;
    private int length;
    private int defaultV;
    private int lowV;
    private int highV;
    private int jump;
    private int match_length;
    private int fixed_length;
    private int offsets[];

    public TABLESWITCH() {
    }

    public String getName() {
        return "TABLESWITCH";
    }

    public int getOp() {
        return 170;
    }

    public int length() {
        return length;
    }

    public void read(DataInputStream din)
            throws IOException {
        int ss = getOffset();
        System.out.println((new StringBuilder()).append("The Table Switch code Offset is").append(ss).toString());
        int padding = (ss + 1 + 3 & -4) - ss - 1;
        for (int i = 0; i < padding; i++)
            din.read();

        defaultV = din.read() << 24 | din.read() << 16 | din.read() << 8 | din.read();
        lowV = din.read() << 24 | din.read() << 16 | din.read() << 8 | din.read();
        highV = din.read() << 24 | din.read() << 16 | din.read() << 8 | din.read();
        match_length = (highV - lowV) + 1;
        fixed_length = (short) (13 + match_length * 4);
        length = (short) (fixed_length + padding);
        offsets = new int[match_length];
        for (int i = 0; i < match_length; i++)
            offsets[i] = din.readInt();

    }

    public int getDefault() {
        return defaultV;
    }

    public void setDefault(int dv) {
        defaultV = dv;
    }

    public int[] getOffsets() {
        return offsets;
    }

    public void write(DataOutputStream dout)
            throws IOException {
        int ss = getOffset();
        int padding = (ss + 1 + 3 & -4) - ss - 1;
        dout.write(170);
        for (int i = 0; i < padding; i++)
            dout.write(0);

        dout.writeInt(defaultV);
        dout.writeInt(lowV);
        dout.writeInt(highV);
        for (int i = 0; i < offsets.length; i++)
            dout.writeInt(offsets[i]);

    }

    public int getOffset() {
        return offset;
    }

    public String getDescrption() {
        String ret = "";
        return ret;
    }

    public void setOffset(int off) {
        offset = off;
    }
}